import PublicFooter from './publicFooter'

function plugin(VueConstructor) {
    VueConstructor.component('PublicFooter', PublicFooter)
    VueConstructor.filter('dateFormat', dateFormat)
}

let dateFormat = function (val, str) {
    //使用{{ itme.st  | dateFormat('MM月DD日 hh时')}}

    let _d = new Date(val),
        YYYY = _d.getFullYear(),
        MM = _d.getMonth() + 1,
        DD = _d.getDate(),
        hh = _d.getHours(),
        mm = _d.getMinutes(),
        ss = _d.getSeconds()

    // 需要把一位的数字转为两位
    MM = MM > 9 ? MM : `0${MM}`
    DD = DD > 9 ? DD : `0${DD}`
    hh = hh > 9 ? hh : `0${hh}`
    mm = mm > 9 ? mm : `0${mm}`
    ss = ss > 9 ? ss : `0${ss}`
    let obj = { YYYY, MM, DD, hh, mm, ss }
    return str.replace(/(YYYY)|(MM)|(DD)|(hh)|(mm)|(ss)/g, function (_s) {
        return obj[_s]
    })
}

export default plugin